package com.dao.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.apache.log4j.Logger;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Component;
import net.sf.json.JSONObject;
import com.bean.Stay;
import com.dao.StayDao;
import com.util.DateUtil;
import com.util.LoggerUtil;

@Component
public class StayDaoImpl implements StayDao {

	public static Logger logger=Logger.getLogger(StayDaoImpl.class);
	@Autowired
	private MongoTemplate mongoTemplate;
	
	
	@Override
	public Map<String, Object> insertStay(String times,String mId, String lId,String type,String deviceType,
			JSONObject logs) {
		Map<String, Object> map=new HashMap<>();
		try {
			Stay stay=new Stay(times,new ObjectId(lId), new ObjectId(mId),type,DateUtil.formatDateToStrAll(new Date()),deviceType);
			mongoTemplate.insert(stay);
			map.put("code", "0");
			LoggerUtil.backlogsSuccess(logs, logger);
		} catch (Exception e) {
			e.printStackTrace();
			map.put("code", "101");
			LoggerUtil.backlogsFalseError(logs, logger,e);
			return map;
		}
		return map;
	}
}
